﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using QuocHoi_TV_Frontend.Models;
using MvcPaging;
namespace QuocHoi_TV_Frontend.Controllers
{
    public class DefaultController : MenuController
    {
        //
        // GET: /Default/

        public ActionResult Home(string date, bool? active, int? page)
        {
            string dateW = DateTime.Now.ToString();
            List<DateOfWeekItem> dateinweek = UtilDate.GetAlldayInWeek(DateTime.Parse(dateW));
            ViewBag.lstdateofweek = dateinweek;
            if ((date == "") || (date == null))
            {
                date = dateW;
                active = false;
            }

            ViewData["active"] = active;
            ViewData["date"] = date;
            int currentPageIndex = page.HasValue ? page.Value : 1;  
            ViewBag.lstlastestNews = DataModels.GetLastestNews(5);
            
            ViewBag.lstcatehadnews = DataModels.GetCateHaveNews(100);
            List<News> lstnews = DataModels.GetNewsByDate(DateTime.Parse(date), 10);

            //var list = 
            if (Request.IsAjaxRequest())
                return PartialView("_NewsInWeek", lstnews.ToPagedList(currentPageIndex, 3));
            else
                return View(lstnews.ToPagedList(currentPageIndex, 3));
        }
       
    }
}
